package cn.wolfcode.luowowo.article.domain;

import cn.wolfcode.luowowo.comment.domain.ViewpointRefComment;
import cn.wolfcode.luowowo.common.domain.BaseDomain;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Setter
@Getter
public class ViewpointComment extends BaseDomain {
    //景点id
    private Long viewpointId;
    //用户
    private UserInfo user;
    //评论时间
    private Date createTime;
    //评论内容
    private String comment;
    //评论图片
    private String imageUrl;
    //评论图片
    private String[] imageUrls;
    //总体评价
    private Integer rank;
    //风光评价
    private Integer scene_rank;
    //特色评价
    private Integer feature_rank;
    //服务评价
    private Integer service_rank;
    //点赞数
    private Integer thumbupnum = 0;
    //点赞用户的ids
    private List<Long> thumbuplist = new ArrayList<>();
    //关联评论
    private List<ViewpointRefComment> refComments;


    public String getCoverUrl() {
        if (imageUrls == null) {
            return null;
        }

        StringBuilder sb = new StringBuilder();
        for (String cu : imageUrls) {
            sb.append(cu).append(",");
        }
        sb.deleteCharAt(sb.length() - 1);
        imageUrl = sb.toString();
        return imageUrl;
    }

    public String[] getCoverUrls() {
        if (!StringUtils.hasLength(imageUrl)) {
            return null;
        }
        String[] vals = imageUrl.split(",");
        imageUrls = new String[vals.length];
        for (int i = 0; i < vals.length; i++) {
            imageUrls[i] = vals[i];
        }
        return imageUrls;
    }


}